package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.web.admin.custom.convert.StringToBaseEnumConverterFactory;
import com.atguigu.lease.web.admin.custom.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName WebMovConfig
 * @Author heartFade
 * @Date 2025-05-01 21:32
 * @Version 1.0
 * @Description TODO
 **/
@Configuration
@PropertySource("classpath:application.yaml")
public class WebMovConfig implements WebMvcConfigurer {
    @Autowired
    StringToBaseEnumConverterFactory stringToBaseEnumConverterFactory;
   @Value("${admin.auth.path-patterns.include}")
   private String include;
   @Value("${admin.auth.path-patterns.exclude}")
   private String exclude;
    @Autowired
    TokenInterceptor tokenInterceptor;
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(stringToBaseEnumConverterFactory);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor).addPathPatterns(include).excludePathPatterns(exclude);
    }
}
